<?php
include('connection/connection.php');
include('config.php');
include('header.php');
include('menu.php');
?>
<html>
<head>
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<title>Delete Forms</title>
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
</head>
<?php
if(isset($_POST['delete']))
{
		$fclick = true;
		$frm_name=$_POST['frm_name'];
		//echo "<br>";
		$form_no=$_POST['form_no'];
		$form_no=trim($form_no);
		if($frm_name==1 || $frm_name==4) //Q-1 or RWSS
		{
			if($frm_name==1)
			{
				$form_name="Q1";
			}
			if($frm_name==4)
			{
				$form_name="Q1RWSS";
			}
			$q1_del_tanker="DELETE FROM tbl_dtls_q1_tanker where loc_id IN ($form_no)";
			$res1_del_tanker=mysql_query($q1_del_tanker);	
			
			$q1_del_critical="DELETE FROM tbl_dtls_q1_critical where loc_id IN ($form_no)";
			$res1_del_critical=mysql_query($q1_del_critical);	
			
			$q1_del_last="DELETE FROM tbl_dtls_q1_last where loc_id IN ($form_no)";
			$res1_del_last=mysql_query($q1_del_last);
				
			$q1_del_psp="DELETE FROM tbl_dtls_q1_psp where loc_id IN ($form_no)";
			$res1_del_psp=mysql_query($q1_del_psp);
				
			$q1_del_pipe="DELETE FROM tbl_dtls_q1_pipeline_ris_dis where loc_id IN ($form_no)";
			$res1_del_pipe=mysql_query($q1_del_pipe);	
			
			$q1_del_reserv="DELETE FROM tbl_dtls_q1_reserv where loc_id IN ($form_no)";
			$res1_del_reserv=mysql_query($q1_del_reserv);
				
			$q1_del_asset="DELETE FROM tbl_dtls_q1_asset where loc_id IN ($form_no)";
			$res1_del_asset=mysql_query($q1_del_asset);
				
			$q1_del_sws="DELETE FROM tbl_dtls_q1_sws where loc_id IN ($form_no)";
			$res1_del_sws=mysql_query($q1_del_sws);
				
			$q1_del_unhabit="DELETE FROM tbl_dtls_q1_unhabit where loc_id IN ($form_no)";
			$res1_del_unhabit=mysql_query($q1_del_unhabit);
				
			$q1_del_oh="DELETE FROM tbl_dtls_q1_oh where loc_id IN ($form_no)";
			$res1_del_oh=mysql_query($q1_del_oh);	
			
			$q1_del_main="DELETE FROM tbl_dtls_q1_main where id IN ($form_no)";
			$res1_del_main=mysql_query($q1_del_main);
			$cnt1=mysql_affected_rows();	
			if($res1_del_main)
			{
				if($cnt1 == 0)
				{
					echo'<span class="successmssg">Now You have no Form Ids, those you want to delete</span>';
				}
				else
				{
					$qr_history="INSERT INTO tbl_dtls_delete_history (form_name, form_id, date) VALUES ('$form_name', '$form_no', NOW())";
					$res_history=mysql_query($qr_history);
					echo '<span class="successmssg">You have successfuly deleted ' . $cnt1 . ' Form Ids and Form Ids are ' . $form_no .'</span>';
					exit;
				}
			}
			
		}
		
		if($frm_name==2) //Q-2
		{
			if($frm_name==2)
			{
				$form_name="Q2";
			}
			$q2_del_tanker="DELETE FROM tbl_dtls_q2_tanker where q2_id IN ($form_no)";
			$res2_del_tanker=mysql_query($q2_del_tanker);
			
			$q2_del_critical="DELETE FROM tbl_dtls_q2_critical where q2_id IN ($form_no)";
			$res2_del_critical=mysql_query($q2_del_critical);
			
			$q2_del_hp="DELETE FROM tbl_dtls_q2_hp_status where q2_id IN ($form_no)";
			$res2_del_hp=mysql_query($q2_del_hp);
			
			$q2_del_unhabit="DELETE FROM tbl_dtls_q2_unhabit where q2_id IN ($form_no)";
			$res2_del_unhabit=mysql_query($q2_del_unhabit);
			
			$q2_del_habit="DELETE FROM tbl_dtls_q2_habit where q2_id IN ($form_no)";
			$res2_del_habit=mysql_query($q2_del_habit);
			
			$q2_del_main="DELETE FROM tbl_dtls_q2_main where id IN ($form_no)";
			$res2_del_main=mysql_query($q2_del_main);
			$cnt2=mysql_affected_rows();	
			if($res2_del_main)
			{
				if($cnt2 == 0)
				{
					echo'<span class="successmssg">Now You have no Form Ids, those you want to delete</span>';
				}
				else
				{
					$qr_history="INSERT INTO tbl_dtls_delete_history (form_name, form_id, date) VALUES ('$form_name', '$form_no', NOW())";
					$res_history=mysql_query($qr_history);
					echo '<span class="successmssg">You have successfuly deleted ' . $cnt2 . ' Form Ids and Form Ids are ' . $form_no .'</span>';
					exit;
				}
			}
			
		}
		
		if($frm_name==3) // Q-3
		{
			if($frm_name==3)
			{
				$form_name="Q3";
			}
			$q3_del_psp="DELETE FROM tbl_dtls_q3_psp where loc_id IN ($form_no)";
			$res3_del_psp=mysql_query($q3_del_psp);
			
			$q3_del_reserv2="DELETE FROM tbl_dtls_q3_reserv2 where loc_id IN ($form_no)";
			$res3_del_reserv2=mysql_query($q3_del_reserv2);
			
			$q3_del_supply_infra_ground="DELETE FROM tbl_dtls_q3_supply_infra_ground where loc_id IN ($form_no)";
			$res3_del_supply_infra_ground=mysql_query($q3_del_supply_infra_ground);
			
			$q3_del_ranking="DELETE FROM tbl_dtls_q3_ranking where loc_id IN ($form_no)";
			$res3_del_ranking=mysql_query($q3_del_ranking);
			
			$q3_del_tanker_supply="DELETE FROM tbl_dtls_q3_tanker_supply where loc_id IN ($form_no)";
			$res3_del_tanker_supply=mysql_query($q3_del_tanker_supply);
			
			$q3_del_traditional_src="DELETE FROM tbl_dtls_q3_traditional_src where loc_id IN ($form_no)";
			$res3_del_traditional_src=mysql_query($q3_del_traditional_src);
			
			$q3_del_reservoirs="DELETE FROM tbl_dtls_q3_reservoirs where loc_id IN ($form_no)";
			$res3_del_reservoirs=mysql_query($q3_del_reservoirs);
			
			$q3_del_water_source_detail="DELETE FROM tbl_dtls_q3_water_source_detail where loc_id IN ($form_no)";
			$res3_del_water_source_detail=mysql_query($q3_del_water_source_detail);
			
			$q3_del_last="DELETE FROM tbl_dtls_q3_last where loc_id IN ($form_no)";
			$res3_del_last=mysql_query($q3_del_last);
			
			$q3_del_water_safe="DELETE FROM tbl_dtls_q3_water_safe where loc_id IN ($form_no)";
			$res3_del_water_safe=mysql_query($q3_del_water_safe);
			
			$q3_del_water_source="DELETE FROM tbl_dtls_q3_water_source where loc_id IN ($form_no)";
			$res3_del_water_source=mysql_query($q3_del_water_source);
			
			$q3_del_water_status="DELETE FROM tbl_dtls_q3_water_status where loc_id IN ($form_no)";
			$res3_del_water_status=mysql_query($q3_del_water_status);
			
			$q3_del_unhabit="DELETE FROM tbl_dtls_q3_unhabit where loc_id IN ($form_no)";
			$res3_del_unhabit=mysql_query($q3_del_unhabit);
			
			$q3_del_habit="DELETE FROM tbl_dtls_q3_habit where loc_id IN ($form_no)";
			$res3_del_habit=mysql_query($q3_del_habit);
			
			$q3_del_loc="DELETE FROM tbl_dtls_q3_loc where id IN ($form_no)";
			$res3_del_loc=mysql_query($q3_del_loc);
			$cnt3=mysql_affected_rows();
			if($res3_del_loc)
			{
				if($cnt3 == 0)
				{
					echo'<span class="successmssg">Now You have no Form Ids, those you want to delete</span>';
				}
				else
				{
					$qr_history="INSERT INTO tbl_dtls_delete_history (form_name, form_id, date) VALUES ('$form_name', '$form_no', NOW())";
					$res_history=mysql_query($qr_history);
					echo '<span class="successmssg">You have successfuly deleted ' . $cnt3 . ' Form Ids and Form Ids are ' . $form_no .'</span>';
					exit;
				}	
			}
			
		}
		
		if($frm_name==5) //UFW
		{
			if($frm_name==5)
			{
				$form_name="UFW";
			}
			$quf_del_reserv_detail="DELETE FROM tbl_dtls_ufw_reserv_detail where loc_id IN ($form_no)";
			$resuf_del_reserv_detail=mysql_query($quf_del_reserv_detail);
			
			$quf_del_reserv_detail="DELETE FROM tbl_dtls_ufw_reserv_detail where loc_id IN ($form_no)";
			$resuf_del_reserv_detail=mysql_query($quf_del_reserv_detail);
			
			$quf_del_pump_detail="DELETE FROM tbl_dtls_ufw_pump_detail where loc_id IN ($form_no)";
			$resuf_del_pump_detail=mysql_query($quf_del_pump_detail);
			
			$quf_del_num_pump_reserv="DELETE FROM tbl_dtls_ufw_num_pump_reserv where loc_id IN ($form_no)";
			$resuf_del_num_pump_reserv=mysql_query($quf_del_num_pump_reserv);
			
			$quf_del_pump_num="DELETE FROM tbl_dtls_ufw_pump_num where loc_id IN ($form_no)";
			$resuf_del_pump_num=mysql_query($quf_del_pump_num);
			
			$quf_del_unhabit="DELETE FROM tbl_dtls_ufw_unhabit where loc_id IN ($form_no)";
			$resuf_del_unhabit=mysql_query($quf_del_unhabit);
			
			$quf_del_habit="DELETE FROM tbl_dtls_ufw_habit where loc_id IN ($form_no)";
			$resuf_del_habit=mysql_query($quf_del_habit);
			
			$quf_del_src_village="DELETE FROM tbl_dtls_ufw_src_village where loc_id IN ($form_no)";
			$resuf_del_src_village=mysql_query($quf_del_src_village);
			
			$quf_del_main="DELETE FROM tbl_dtls_ufw_main where id IN ($form_no)";
			$resuf_del_main=mysql_query($quf_del_main);
			$cnt4=mysql_affected_rows();
			if($resuf_del_main)
			{
				if($cnt4 == 0)
				{
					echo'<span class="successmssg">Now You have no Form Ids, those you want to delete</span>';
				}
				else
				{
					$qr_history="INSERT INTO tbl_dtls_delete_history (form_name, form_id, date) VALUES ('$form_name', '$form_no', NOW())";
					$res_history=mysql_query($qr_history);
					echo '<span class="successmssg">You have successfuly deleted ' . $cnt4 . ' Form Ids and Form Ids are ' . $form_no .'</span>';
					exit;
				}	
			}
		}
		
		if($frm_name==6) //Critical
		{
			if($frm_name==6)
			{
				$form_name="Critical";
			}
			$qcrit_del_critical_unhabit="DELETE FROM tbl_dtls_critical_unhabit where loc_id IN ($form_no)";
			$rescrit_del_critical_unhabit=mysql_query($qcrit_del_critical_unhabit);
			
			$qcrit_del_critical_habit="DELETE FROM tbl_dtls_critical_habit where loc_id IN ($form_no)";
			$rescrit_del_critical_habit=mysql_query($qcrit_del_critical_habit);
			
			$qcrit_del_critical="DELETE FROM tbl_dtls_critical where id IN ($form_no)";
			$rescrit_del_critical=mysql_query($qcrit_del_critical);
			$cnt5=mysql_affected_rows();
			if($rescrit_del_critical)
			{
			if($cnt5 == 0)
				{
					echo'<span class="successmssg">Now You have no Form Ids, those you want to delete</span>';
				}
				else
				{
					$qr_history="INSERT INTO tbl_dtls_delete_history (form_name, form_id, date) VALUES ('$form_name', '$form_no', NOW())";
					$res_history=mysql_query($qr_history);
					echo '<span class="successmssg">You have successfuly deleted ' . $cnt5 . ' Form Ids and Form Ids are ' . $form_no .'</span>';
					exit;
				}	
			}
		}
		
		//echo "Success";
}
else
{
	$fclick = false;
	$flag=0;
}		
?>
<body>
<div align="center">
<form method="post" name="f1" action='' onSubmit="return cnfrm();">
<table border="0" width="746" id="table1" cellspacing="0" cellpadding="0">
<tr bgcolor="FF9966">
		<td height="29" align="left" valign="top" bgcolor="#FF9966" colspan="4">&nbsp;</td>
	</tr>
	<tr>
	<td bgcolor="#E5E5E5" align="center" colspan="4">
	<span lang="en-us">&nbsp;</span><span lang="en-us" style="font-size: 8.5pt"><font face="Verdana" color="#006699"><b>Delete Questionnaires</b></font></span></td>
</tr>
<tr><td bgcolor="#E5E5E5" align="left" colspan="4">&nbsp;</td>
</tr>
<tr><td align="left" colspan="4">&nbsp;</td>
</tr>
<tr><td width="29%" height="23"><font face="Verdana" style="font-size: 9pt" color="#000000">&nbsp;Select Questionnaire</font></td>
<td width="71%">
<!--<select name='frm_name' id='frm_name' class="txt">
<option selected value="0">Select one</option>
<?php
/*$qryQuestionnaire="SELECT DISTINCT q_name,q_id FROM questionnaire order by q_id";
$recQuestionnaire=mysql_query($qryQuestionnaire);  
while($rowQuestionnaire = mysql_fetch_array($recQuestionnaire)) 
{ 
	if($rowQuestionnaire['q_id']==$questionnaire)
	{
	?>
		<option selected value=<?php echo $rowQuestionnaire['q_id'];?>><?php echo $rowQuestionnaire['q_name'];?></option>
	<?php
	}
	else
	{
	?>
		<option value=<?php echo $rowQuestionnaire['q_id'];?>><?php echo $rowQuestionnaire['q_name'];?></option>
	<?php
	}
}*/
?>
</select>-->
<select name='frm_name' id='frm_name' class="txt">
<option selected value="0">Select one</option>
		<?php 
			foreach($form_delete as $key=>$val)
			{
		   		echo "<option value=$key>$val</option>";
			}
		?>
</select>	
</td></tr>
<tr><td align="left" colspan="4">&nbsp;</td>
<tr>
	<td height="26"><font face="Verdana" style="font-size: 9pt" color="#000000">&nbsp;Enter Form No</font></td>
	<td><input type="text" name="form_no" id="form_no" class="txt_new" onBlur="numeric_del(this)"><font face="Verdana" style="font-size: 8.5pt" color="#FF0000">*Delete Maximum 20 Form-Ids at a time<br>*Enter Only Numeric Value Of Form-Ids separate by Comma.(Eg- 2345,4567,6789)</font></td>
</tr>
<tr><td align="left" colspan="4">&nbsp;</td>
<tr>
	<td>&nbsp;</td>
	<td><input type="submit" name="delete" id="delete" value="Delete"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
